
package laya.semi.process;

public class FieldMapping
{
	private String m_oFieldId = null;
	private String m_oDefValue = null;
	private String m_oFieldTypeName = "java.lang.Object";
	private String m_oPrototypeName = m_oFieldTypeName;
	private int m_nFieldType = FT_CUSTOM;
	private int m_nPrototype = m_nFieldType;
	private String m_oNativeName = null;
	private boolean m_bIsKey = false;
	private boolean m_bNeedConvert = false;
	private String m_oConvertFormat = null; // for future
	private String m_oConvertor = null;
	
	public static final int FT_BOOLEAN = 0x01;	// boolean
	public static final int FT_INT = 0x02;		// int
	public static final int FT_LONG = 0x03;		// long
	public static final int FT_FLOAT = 0x04;	// float
	public static final int FT_DOUBLE = 0x05;	// double
	public static final int FT_SHORT = 0x06;	// short
	public static final int FT_CUSTOM = 0x0f;	// ...
	
	public FieldMapping(String oFieldId)
	{
		m_oFieldId = oFieldId;
	}
	
	public void setProcessKey(boolean bIsKey)
	{
		m_bIsKey = bIsKey;
	}
	
	public boolean isProcessKey()
	{
		return m_bIsKey;
	}
	
	public void setFieldTypeName(String oValue)
	{
		m_oFieldTypeName = oValue.trim();
		m_nFieldType = getFieldTypeByName(m_oFieldTypeName);
		
		m_oPrototypeName = m_oFieldTypeName;
		m_nPrototype = m_nFieldType;
		m_bNeedConvert = false;
	}
	
	public void setPrototypeName(String oValue)
	{
		if (null != oValue)
		{
			m_oPrototypeName = oValue.trim();
			m_nPrototype = getFieldTypeByName(m_oPrototypeName);
			m_bNeedConvert = true;
		}
		else
		{
			m_oPrototypeName = m_oFieldTypeName;
			m_nPrototype = m_nFieldType;
			m_bNeedConvert = false;
		}
	}
	
	public void setDefaultValue(String oValue)
	{
		m_oDefValue = oValue;
	}
	
	public void setNativeName(String oValue)
	{
		m_oNativeName = oValue.trim();
	}

	public void setConvertFormat(String oValue)
	{
		m_oConvertFormat = oValue.trim();
	}

	public void setConvertor(String oValue)
	{
		m_oConvertor = oValue.trim();
	}

	public String getFieldId()
	{
		return m_oFieldId;
	}
	
	public String getFieldTypeName()
	{
		return m_oFieldTypeName;
	}
	
	public String getPrototypeName()
	{
		return m_oPrototypeName;
	}
	
	public int getFieldType()
	{
		return m_nFieldType;
	}
	
	public int getPrototype()
	{
		return m_nPrototype;
	}
	
	public String getNativeName()
	{
		return m_oNativeName;
	}
	
	public String getDefaultValue()
	{
		return m_oDefValue;
	}
	
	public String getConvertFormat()
	{
		return m_oConvertFormat;
	}
	
	public String getConvertor()
	{
		return m_oConvertor;
	}
	
	public boolean needConvert()
	{
		return m_bNeedConvert;
	}
	
	private int getFieldTypeByName(String oTypeName)
	{
		int r = FT_CUSTOM;
		
		if ("int".equals(oTypeName))
			r = FT_INT;		// int
		else if ("long".equals(oTypeName))
			r = FT_LONG;		// long
		else if ("float".equals(oTypeName))
			r = FT_FLOAT;	// float
		else if ("double".equals(oTypeName))
			r = FT_DOUBLE;	// double
		else if ("boolean".equals(oTypeName))
			r = FT_BOOLEAN;	// double
		else if ("short".equals(oTypeName))
			r = FT_SHORT;	// short
		
		return r;
	}
}
